package acwing.dfs;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 大臣的旅费
 *
 * @author yang
 * @date 2021/12/9
 */
public class 大臣的旅费 {

    static int N = 100010,M = 200010;
    static int[] h = new int[N];
    static int[] e = new int[M];
    static int[]ne = new int[M];
    static int[]w = new int[M];
    static int[] dist = new int[N];
    static int idx = 0;

    static void add(int a, int b, int c) {
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Arrays.fill(h, -1);
        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            add(a,b,c);
            add(b,a,c);
        }
        dfs(1, -1, 0);
        int u = 1;
        for (int i = 2; i <=n; i++) {
            if(dist[i] > dist[u]) {
                u = i;
            }
        }
        dfs(u, -1,0);
        int max = dist[1];
        for (int i = 2; i <= n; i++) {
            if (dist[i] > max) {
                max = dist[i];
            }
        }
        System.out.println(max * 10 + ((long)(max + 1) * max) / 2);
    }

    private static void dfs(int u, int father, int distance) {

        dist[u] = distance;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int j = e[i];
            if (j != father) {
                dfs(j,u,distance + w[i]);
            }
        }
    }
}
